package com.own.component.common.login.parent;

import com.own.component.common.login.AuthenticationLoginUser;
import com.own.component.common.login.user.BaseLoginUser;
import com.own.component.common.login.user.BasePermissionUser;
import com.own.component.common.login.user.DefaultLoginUser;
import com.own.component.common.login.user.DefaultPermissionUser;
import com.own.component.common.login.util.BaseUtil;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * ParentAuthenticationDefaultLoginUser
 *
 * @author chenxueli
 * @date 2023-08-10 16:22:34
 */
@Slf4j
public class ParentAuthenticationDefaultLoginUser implements ParentAuthenticationLoginUser {

    private final AuthenticationLoginUser authenticationLoginUser;

    public ParentAuthenticationDefaultLoginUser(AuthenticationLoginUser authenticationLoginUser) {
        this.authenticationLoginUser = authenticationLoginUser;
    }

    /**
     * 基本类用户信息
     *
     * @return 基本类用户信息
     */
    @Override
    public BaseLoginUser loginUser() {
        return BaseUtil.get(DefaultLoginUser.DEFAULT, authenticationLoginUser::loginUser);
    }

    /**
     * 权限类用户信息
     *
     * @param loginUser 登录的用户信息
     * @return 权限类用户信息
     */
    @Override
    public BasePermissionUser permissionUser(BaseLoginUser loginUser) {
        return BaseUtil.get(DefaultPermissionUser.DEFAULT, () -> authenticationLoginUser.permissionUser(loginUser));
    }

    /**
     * 基本类用户信息
     *
     * @param userId 用户id
     * @return 基本类用户信息
     */
    @Override
    public List<BaseLoginUser> loginUser(Long userId) {
        return BaseUtil.get(null, () -> authenticationLoginUser.loginUser(userId));
    }

    /**
     * 权限类用户信息
     *
     * @param userId 用户id
     * @return 权限类用户信息
     */
    @Override
    public List<BasePermissionUser> permissionUser(Long userId) {
        return BaseUtil.get(null, () -> authenticationLoginUser.permissionUser(userId));
    }

}
